def selection_sort(nums: list[int]):
    """选择排序"""  # 升序：把最小值“选择”到左边
    
    n = len(nums)
    for i in range(n):  # 外循环：左 [0, n-1] 右
        m = i
        for j in range(i + 1, n):  # 内循环：左 [i+1, n-1] 右
            if nums[j] < nums[m]:
                m = j
        nums[i], nums[m] = nums[m], nums[i]


if __name__ == "__main__":
    nums = [4, 1, 3, 1, 5, 2]
    selection_sort(nums)
    print("排序完成后 nums =", nums)
    # 排序完成后 nums = [1, 1, 2, 3, 4, 5]
